package at.fhj.itm10.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class CustomerPanel extends JPanel implements ActionListener
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 281832022278798815L;

	private MainWindow parent;

	// GUI elements of the customer car panel
	private JPanel pnlBase;
	private JPanel pnlCustomer;
	private JPanel pnlCar;
	private JPanel pnlButtons;

	private JButton btnSaveEdit;
	private JButton btnCancel;

	// Elements for the customer
	private JLabel lblFirstname;
	private JLabel lblLastname;
	private JLabel lblAddress;
	private JLabel lblPostcode;
	private JLabel lblCity;
	private JLabel lblMail;

	private JTextField tfFirstName;
	private JTextField tfLastName;
	private JTextField tfAddress;
	private JTextField tfPostcode;
	private JTextField tfCity;
	private JTextField tfMail;

	// Elements for the car
	private JLabel lblLicensePlate;
	private JLabel lblBrand;
	private JLabel lblType;

	private JTextField tfLicensePlate;
	private JTextField tfBrand;
	private JTextField tfType;

	public CustomerPanel(MainWindow parent)
	{
		this.parent = parent;
		initContent();
	}

	private void initContent()
	{
		this.setLayout(new BorderLayout());

		this.pnlBase = new JPanel();
		pnlBase.setLayout(new GridLayout(0, 2));

		// customerpanel
		this.pnlCustomer = new JPanel(new GridLayout(0, 2));
		this.pnlCustomer.setBorder(BorderFactory.createTitledBorder("Kunde"));
		this.lblFirstname = new JLabel("Vorname: ");
		this.lblLastname = new JLabel("Nachname: ");
		this.lblAddress = new JLabel("Adresse: ");
		this.lblPostcode = new JLabel("PLZ: ");
		this.lblCity = new JLabel("Ort: ");
		this.lblMail = new JLabel("Mail: ");

		this.tfFirstName = new JTextField(20);
		this.tfLastName = new JTextField(20);
		this.tfAddress = new JTextField(20);
		this.tfPostcode = new JTextField(20);
		this.tfCity = new JTextField(20);
		this.tfMail = new JTextField(20);

		this.pnlCustomer.add(lblFirstname);
		this.pnlCustomer.add(tfFirstName);
		this.pnlCustomer.add(lblLastname);
		this.pnlCustomer.add(tfLastName);
		this.pnlCustomer.add(lblAddress);
		this.pnlCustomer.add(tfAddress);
		this.pnlCustomer.add(lblPostcode);
		this.pnlCustomer.add(tfPostcode);
		this.pnlCustomer.add(lblCity);
		this.pnlCustomer.add(tfCity);
		this.pnlCustomer.add(lblMail);
		this.pnlCustomer.add(tfMail);

		// carpanel
		this.pnlCar = new JPanel(new GridLayout(0, 2));
		this.pnlCar.setBorder(BorderFactory.createTitledBorder("Fahrzeug"));

		this.lblLicensePlate = new JLabel("Kennzeichen: ");
		this.lblBrand = new JLabel("Marke: ");
		this.lblType = new JLabel("Typ: ");

		this.tfLicensePlate = new JTextField(20);
		this.tfBrand = new JTextField(20);
		this.tfType = new JTextField(20);

		this.pnlCar.add(lblLicensePlate);
		this.pnlCar.add(tfLicensePlate);
		this.pnlCar.add(lblBrand);
		this.pnlCar.add(tfBrand);
		this.pnlCar.add(lblType);
		this.pnlCar.add(tfType);

		this.pnlBase.add(pnlCustomer);
		this.pnlBase.add(pnlCar);

		this.add(pnlBase, BorderLayout.CENTER);

		this.pnlButtons = new JPanel(new FlowLayout());
		this.btnSaveEdit = new JButton("Speichern");
		this.pnlButtons.add(btnSaveEdit);
		this.btnCancel = new JButton("Abbrechen");
		this.btnCancel.addActionListener(this);
		this.pnlButtons.add(btnCancel);
		this.add(pnlButtons, BorderLayout.SOUTH);

	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		if (e.getSource().equals(btnCancel))
		{
			this.setVisible(false);
		}

	}

}
